package cn.itcast.controller;

import cn.itcast.domain.kefang;
import cn.itcast.domain.kehu;
import cn.itcast.service.impl.kefangService;
import cn.itcast.service.impl.kehuService;
import com.sun.org.apache.xpath.internal.operations.Bool;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.Date;

@Controller
@RequestMapping(path="/insert")
public class InsertController {
    @Autowired
    private kefangService kefangservice;
    @Autowired
    private kehuService kehuservice;

//添加客房，返回首页
    @RequestMapping(path = "/kefang")
    public void kefang(kefang kf, HttpServletRequest request, HttpServletResponse response) throws IOException {
        kf.setStatue(0);
        kefangservice.insertkefang(kf);
        response.sendRedirect(request.getContextPath()+"/user/jump");
        return ;
    }


//填写客户信息，返回首页,用于FillIn_kehu.jsp
    @RequestMapping(path = "/kehu")
    public void kehu(kehu kh, HttpServletRequest request, HttpServletResponse response) throws IOException {
        Date date = new Date(new java.util.Date().getTime());
        kh.setInTime(date);
        kefang  kf=kefangservice.findkefangByNum(kh.getNum());
        kf.setStatue(1);
        kehuservice.insertkehu(kh);
        kefangservice.updatekefang(kf);
        response.sendRedirect(request.getContextPath()+"/user/jump");
        return ;
    }


}
